package tp.pr5.gui;

import java.awt.BorderLayout;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import tp.pr5.Direction;

public class RobotHeading extends JPanel {	
	JLabel image;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Defalut constructor
	 */
	public RobotHeading(){		
		this.setLayout(new BorderLayout());
		init();
	}
	/**
	 * Creates the components of the panel
	 */
	private void init(){
		/*
		 * Creates the component
		 */
		ImageIcon im = createImageIcon("headingIcons/walleEast.png","Heading east");
		image = new JLabel(im);
		
		/*
		 * Adds the component
		 */		
		this.add(image, BorderLayout.CENTER);
	}
	
	/** Returns an ImageIcon, or null if the path was invalid. */
	private ImageIcon createImageIcon(String path,
	                                           String description) {
	    java.net.URL imgURL = getClass().getResource(path);
	    if (imgURL != null) {
	        return new ImageIcon(imgURL, description);
	    } else {
	        System.err.println("Couldn't find file: " + path);
	        return null;
	    }
	}
	
	public void refresh(Direction dir){
		if(dir.equals(Direction.NORTH)){
			ImageIcon im = createImageIcon("headingIcons/walleNorth.png","Heading east");
			image.setIcon(im);
		}else if(dir.equals(Direction.WEST)){
			ImageIcon im = createImageIcon("headingIcons/walleWest.png","Heading east");
			image.setIcon(im);
		}else if(dir.equals(Direction.EAST)){
			ImageIcon im = createImageIcon("headingIcons/walleEast.png","Heading east");
			image.setIcon(im);
		}else if(dir.equals(Direction.SOUTH)){
			ImageIcon im = createImageIcon("headingIcons/walleSouth.png","Heading east");
			image.setIcon(im);
		}
	}
}
